<?php if (!defined('ROOT_DIR')) exit('No direct script access!');
/**
 * bootstrap.nct.core.php
 *
 * PHP Version 5
 *
 * DateCreated - December 2, 2011
 * DateModified - January 16, 2012
 * 
 * This will be the main loader and connector in order for the framework to work.
 * 
 * @category  Core
 * @package   Core
 * @author    Ervin Musngi <ervinmusngi@gmail.com>
 * 
 * @copyright 2011 Ervin Musngi
 * @license   http://netcoretech.com Net-Coret-Tech
 * @version   SVN: <tortoise>
 * @link      http://netcoretech.com/php/
 * 
 */

require_once ROOT_DIR.'/'.$application_folder.'/config/route.php';

require_once ROOT_DIR.'/'.$system_folder.'/core/func.nct.core.php';

if (isset($_SERVER['PATH_INFO'])) {
    $uriArray = explode('/', parse_url($_SERVER['PATH_INFO'], PHP_URL_PATH));
    array_shift($uriArray);
} else {
    $uriArray = array();
}

if ( !isset( $uriArray[0]) || $uriArray[0] == '' ) {
    $_controller = $route['default_controller'];
} else {
    $_controller = $uriArray[0];
    unset( $uriArray[0] );
}

if ( ! isset($uriArray[1]) || $uriArray[1] == '' ) {
    $_method = 'index';
} else {
    $_method = $uriArray[1];
    unset( $uriArray[1] );
}

if ( !file_exists(ROOT_DIR.'/'.$application_folder.'/controllers/'.$_controller.'.'.$secure_controller_extension.'.controller.php') ) {
    include_once ROOT_DIR.'/'.$system_folder.'/error/4oh4.php';
    exit();
}
    
require_once ROOT_DIR.'/'.$system_folder.'/core/controller.nct.core.php';

require_once ROOT_DIR.'/'.$system_folder.'/core/model.nct.core.php';

require_once ROOT_DIR.'/'.$application_folder.'/controllers/'.$_controller.'.'.$secure_controller_extension.'.controller.php';

$_current_controller = new $_controller;


if ( method_exists($_current_controller, $_method) && __verify_method_type(get_class($_current_controller), $_method) ) {
    
    try {
        call_user_func_array(array($_current_controller, $_method), $uriArray);
    } catch(Exception $e) {
        
        if ( ERROR_REPORT === true ) {
            include_once ROOT_DIR.'/'.$system_folder.'/error/unkownMethodClass.php';
        }
        
        exit();
    }
} else {
    
    if ( ERROR_REPORT === true ) {
        include_once ROOT_DIR.'/'.$system_folder.'/error/unkownMethodClass.php';
    }
    
    exit();

}
    
    